//
//  LXJFansListCell.swift
//  XJWeiBo
//
//  Created by 李旭杰 on 2017/4/9.
//  Copyright © 2017年 李旭杰. All rights reserved.
//

import UIKit

class LXJFansListCell: UITableViewCell {
    
    /// 数据源属性
    var fansInfo: LXJFansDetailsViewModel? {
        didSet{
            /// 控件赋值
            /// 头像
            profile_image_url.sd_setImage(with: URL(string: (fansInfo?.fansDetails?.avatar_large)!), placeholderImage: UIImage(named: "avatar_default_big"))
            /// 昵称
            screen_name.text = fansInfo?.fansDetails?.screen_name
            /// 认证类型
            verified_type.image = fansInfo?.verifiedTypeImage
            /// 签名
            desc.text = fansInfo?.descript
        }
    }
    
    // MARK: 控件的懒加载
    /// 头像
    fileprivate lazy var profile_image_url: UIImageView = {
        let img = UIImageView()
        /// 设置背景颜色
        img.backgroundColor = UIColor.red
        /// 设置圆角
        img.layer.cornerRadius = 30
        img.layer.masksToBounds = true
        /// 缩放方式
        img.contentMode = .scaleAspectFill
        img.clipsToBounds = true
        return img
    }()
    
    /// 昵称
    fileprivate lazy var screen_name = UILabel(text: "生无可恋的喵星人", font: 14, textColor: UIColor.black, textAlignment: .center)
    
    /// 认证类型
    fileprivate lazy var verified_type: UIImageView = {
        let img = UIImageView()
        /// 这只图片
        img.image = UIImage(named: "avatar_vip")
        return img
    }()
    
    /// 个性签名
    fileprivate lazy var desc = UILabel(text: "不要迷恋姐,姐夫会揍你!", font: 11, textColor: UIColor.darkGray, textAlignment: .center)
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        /// 界面搭建
        setupUI()
    }
    
    /// 不使用 XIB 加载
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: 页面搭建
    fileprivate func setupUI() {
        /// 设置背景颜色
        contentView.backgroundColor = UIColor.white
       
        /// 添加到父视图
        contentView.addSubview(profile_image_url)
        contentView.addSubview(verified_type)
        contentView.addSubview(screen_name)
        contentView.addSubview(desc)
        
        /// 自动布局
        
        profile_image_url.snp.makeConstraints { (make) in
            make.top.leading.equalTo(homeWeiboCellmargin)
            make.size.equalTo(CGSize(width: 60, height: 60))
        }
        
        screen_name.snp.makeConstraints { (make) in
            make.top.equalTo(profile_image_url)
            make.leading.equalTo(profile_image_url.snp.trailing).offset(homeWeiboCellmargin)
        }
        
        verified_type.snp.makeConstraints { (make) in
            make.top.equalTo(screen_name)
            make.leading.equalTo(screen_name.snp.trailing).offset(homeWeiboCellmargin / 2)
        }

        desc.snp.makeConstraints { (make) in
            make.bottom.equalTo(profile_image_url)
            make.leading.equalTo(screen_name)
        }
    }
}
